﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TextTemplating;
using System.Web.Mvc;

namespace MvcT4ViewEngine.Lib.Templating
{
    public class T4Helper
    {

        public static ViewContext GetContext(ITextTemplatingEngineHost h)
        {
            var host = h as T4TemplateHost;
            return host["ViewContext"] as ViewContext;
        }

        public static ViewDataDictionary GetViewData(ITextTemplatingEngineHost h)
        {
            var host = h as T4TemplateHost;
            return (host["ViewContext"] as ViewContext).ViewData;
        }

        public static object GetViewDataObject(ITextTemplatingEngineHost h, string key)
        {
            var host = h as T4TemplateHost;
            return (host["ViewContext"] as ViewContext).ViewData[key];
        }

        public static T GetViewDataObject<T>(ITextTemplatingEngineHost h, string key) where T:class
        {
            var host = h as T4TemplateHost;
            return (host["ViewContext"] as ViewContext).ViewData[key] as T;
        }
        
    }
}
